import React, { Component } from "react";
import "./index.css";

import Header from "./components/Header";
import Main from "./components/Main";
import Footer from "./components/Footer";

import axios from "axios";

export default class App extends Component {
  state = {
    list: [],
  };

  // 组件初始化后去获取接口任务列表
  componentDidMount() {
    this.getTodoList()
  }

  getTodoList = async () => {
    const res = await axios.get("http://localhost:5000/todos");
    this.setState({ list: res.data });
  }


  render() {
    return (
      <section className="todoapp">
        <Header getTodoList={this.getTodoList} />
        <Main list={this.state.list} getTodoList={this.getTodoList}/>
        <Footer />
      </section>
    );
  }
}
